package com.dididoctor.doctor.Utils;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.provider.MediaStore;

import com.dididoctor.doctor.Utils.imageprocess.ABImageProcess;

import java.io.File;

/**
 * 项目名称：PsdApp
 * 类描述：拍照，相册帮助类
 * 创建人：张强
 * 创建时间：2016/1/5 11:41
 * 修改人：
 * 修改时间：2016/1/5 11:41
 * 修改备注：
 */
public class PhotoHelper {
    private Activity mActivity;
    private String capturePath;
    private Context context;

    public final int TO_CAMEIA = 1001;
    public final int TO_PHOTO = 1002;
    public final int TO_ZOOM_PHOTO = 1004;

    public PhotoHelper(Activity activity, String capturePath) {
        this.mActivity = activity;
        this.capturePath = capturePath;
    }
    public PhotoHelper(Context context, String capturePath) {
        this.context = context;
        this.capturePath = capturePath;
    }

    /**
     * 裁剪图片
     *
     * @param uri
     */
    public void startPhotoZoom(Uri uri) {
        ABImageProcess.compressImage2SD(new File(capturePath), capturePath, 712, 960, 85);
        Intent intent = new Intent("com.android.camera.action.CROP");
        intent.setDataAndType(uri, "image/*");
        // crop为true是设置在开启的intent中设置显示的view可以剪裁
        intent.putExtra("crop", "true");
        // aspectX aspectY 是宽高的比例
        //intent.putExtra("aspectX", 1);
        //intent.putExtra("aspectY", 1);
        // outputX,outputY 是剪裁图片的宽高
        //intent.putExtra("outputX", 300);
        //intent.putExtra("outputY", 300);
        intent.putExtra("return-data", false);
        intent.putExtra("noFaceDetection", true);
        intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
        intent.putExtra("output", Uri.fromFile(new File(capturePath))); //保存路径
        intent.putExtra("scale", true);
        mActivity.startActivityForResult(intent, TO_ZOOM_PHOTO);
    }

    /**
     * 拍照
     */
    public void takePhoto() {
        Intent getImageByCamera = new Intent("android.media.action.IMAGE_CAPTURE");
        getImageByCamera.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(capturePath)));
        getImageByCamera.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
        mActivity.startActivityForResult(getImageByCamera, TO_CAMEIA);
    }

    /**
     * 从相册取图片
     */
    public void takePictureFromAlbum() {
        Intent intent = new Intent(Intent.ACTION_PICK);
        intent.setType("image/*");
        mActivity.startActivityForResult(intent, TO_PHOTO);
    }
}
